import QtQuick 2.8
import QtQuick.Controls 2.1
import QtQuick.Layouts 1.2
 
Page {
    id: pageCounter
    title: qsTr("帐号")
    visible: true
 
    property StackView stack: null
 
    Keys.enabled: true
    focus: true
    Keys.onPressed: {
        console.log("key:"+event.key)
        console.log("nativeScanCode:"+event.nativeScanCode)
        console.log("text:"+event.text)
        console.log("******************************")

        if(event.key == Qt.Key_Escape) {
            stack.custPop()
            return;
        }
        event.accepted = true
    }
    header: ToolBar {
        background: Rectangle {
            implicitWidth: 100
            implicitHeight: 40
            opacity: 1
            color: "#3f51b5"
        }
        RowLayout {
            anchors.fill: parent
            ToolButton {
                text: qsTr("‹返回[Esc]")
                onClicked: stack.custPop()
            }
            Label {
                text: "任务计数"
                font.pointSize: 16
                color: '#ffffff'
                elide: Label.ElideRight
                horizontalAlignment: Qt.AlignHCenter
                verticalAlignment: Qt.AlignVCenter
                Layout.fillWidth: true
            }
            // ToolButton {
            //     text: qsTr("⋮")
            //     onClicked: menu.open()
            // }
        }
    }
    Column{
        anchors.fill: parent

        Rectangle{
            width: parent.width
            height: 80
            color: '#2c489c'
            Text{
                width: parent.width
                height: 80
                // horizontalAlignment: Text.AlignHCenter//(1)
                verticalAlignment: Text.AlignVCenter    //垂直居中，控件必须有height才可以使用
                horizontalAlignment: Text.AlignHCenter
                font.pointSize: 20
                font.bold: true
                color: '#91d145'
                text:'答题卡数量'
            }
        }

        Rectangle{
            width: parent.width
            color: '#2c489c'
            height: parent.height - 80
            Text{
                id: counterDisplay
                width: parent.width
                height: 80
                // horizontalAlignment: Text.AlignHCenter//(1)
                verticalAlignment: Text.AlignVCenter    //垂直居中，控件必须有height才可以使用
                horizontalAlignment: Text.AlignHCenter
                font.pointSize: 80
                font.bold: true
                color: '#91d145'
                text:'***'
            }
        }
    }
    Connections{
        target: gCounter
        function onCounterNewValue(value){
            console.log(value)
            if(value < 0){
                counterDisplay.text = '--';
            }else{
                counterDisplay.text = value;
            }
        }
    }
    function beforeDestroy(){
        gCounter.counterStop()
    }
    Component.onCompleted:{
        console.log("onCompleted")
        gCounter.counterStart()
    }
    Component.onDestruction:{
        console.log("onDestruction")
        // gCounter.counterStop()
    }
}